/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package persistence;

import java.io.Serializable;
import java.util.ArrayList;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import persistence.Address;

/**
 *
 * @author ceu
 */
@Entity
@Table(name = "shipment")
@NamedQueries({
    @NamedQuery(name = "Shipment.findAll", query = "SELECT s FROM Shipment s")})
public class Shipment implements Serializable {
    private static final long serialVersionUID = 1L;
   
    private Integer idShipment;
    private Integer numberPackages;
    private Integer volume;
    @Size(max = 40)
    private String notes;
    @NotNull
    private int telephoneOrigin;
    @NotNull
    private int telephoneDestiny;
    private TypePackage typePackage;
    private Address destinyAddress;
    private Address originAddress;
    private Status status;
    private Customer customer;
    private ArrayList<Section> sections;

    

    public Shipment() {
    }

    public Shipment(Integer numberPackages, Integer volume, String notes, int telephoneOrigin, int telephoneDestiny, TypePackage typePackage,
            Address destinyAddress,Address originAddress, Status status, Customer customer, ArrayList sections) {

    this.numberPackages=numberPackages;
    this.volume=volume;
    this.notes=notes;
    this.telephoneOrigin=telephoneOrigin;
    this.telephoneDestiny=telephoneDestiny;
    this.typePackage=typePackage;
    this.destinyAddress=destinyAddress;
    this.originAddress=originAddress;
    this.status=status;
    this.customer=customer;
    this.sections=sections;

    }
    
   
    @Column(name = "number_packages")
    public Integer getNumberPackages() {
        return numberPackages;
    }

    public void setNumberPackages(Integer numberPackages) {
        this.numberPackages = numberPackages;
    }

    @Column(name = "volume")
    public Integer getVolume() {
        return volume;
    }

    public void setVolume(Integer volume) {
        this.volume = volume;
    }

    @Column(name = "notes")
    public String getNotes() {
        return notes;
    }

    public void setNotes(String notes) {
        this.notes = notes;
    }

    @Basic(optional = false)
    @Column(name = "telephone_origin")
    public int getTelephoneOrigin() {
        return telephoneOrigin;
    }

    public void setTelephoneOrigin(int telephoneOrigin) {
        this.telephoneOrigin = telephoneOrigin;
    }

    @Basic(optional = false)
    @Column(name = "telephone_destiny")
    public int getTelephoneDestiny() {
        return telephoneDestiny;
    }

    public void setTelephoneDestiny(int telephoneDestiny) {
        this.telephoneDestiny = telephoneDestiny;
    }

    @JoinColumn(name = "type_package_id", referencedColumnName = "idtype_package", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    public TypePackage getTypePackage() {
        return typePackage;
    }

    public void setTypePackage(TypePackage typePackage) {
        this.typePackage = typePackage;
    }

    @JoinColumn(name = "id_destiny", referencedColumnName = "idAddress")
    // @Column(name="id_destiny")
    @ManyToOne(optional = false, targetEntity=Address.class)
    public Address getDestinyAddress() {
        return destinyAddress;
    }

    public void setDestinyAddress(Address idDestiny) {
        this.destinyAddress = idDestiny;
    }

    @JoinColumn(name = "id_origin", referencedColumnName = "idAddress")
    @ManyToOne()
    public Address getOriginAddress() {
        return originAddress;
    }

    public void setOriginAddress(Address idOrigin) {
        this.originAddress = idOrigin;
    }

    @JoinColumn(name = "status_idstatus", referencedColumnName = "idStatus")
    @ManyToOne(optional = false,targetEntity=Status.class)
    public Status getStatus() {
        return status;
    }

    public void setStatus(Status statusIdstatus) {
        this.status = statusIdstatus;
    }

    @ManyToMany
    @JoinTable(name="shipment_section",joinColumns={@JoinColumn(name="Shipment_idShipment",referencedColumnName="idShipment")},
    inverseJoinColumns={@JoinColumn(name="section_idSection",referencedColumnName="idSection")})
    public ArrayList<Section> getSections() {
        return sections;
    }

    public void setSections(ArrayList<Section> sections) {
        this.sections = sections;
    }

    
    
    
    @JoinColumn(name = "Costumer_idCustomer", referencedColumnName = "idCustomer")
    @ManyToOne(optional = false)
    public Customer getCustomer() {
        return customer;
    }

    public void setCustomer(Customer costumer) {
        this.customer = costumer;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += ( getIdShipment()!= null ? getIdShipment().hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Shipment)) {
            return false;
        }
        Shipment other = (Shipment) object;
        if ((this.getIdShipment() == null && other.getIdShipment() != null) || (this.getIdShipment() != null && !this.idShipment.equals(other.idShipment))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "persistence.Shipment[ shipmentPK=" + getIdShipment() + " ]";
    }

    /**
     * @return the idShipment
     */
    @TableGenerator(
        name="shipmentGen",
        table="JPA_WXS_APP_SEQUENCE_GENERATOR",
        pkColumnName="GEN_KEY",
        valueColumnName="GEN_VALUE",
        pkColumnValue="idShipment",
        allocationSize=1,
        initialValue=0)
        @Id
    @GeneratedValue(strategy=GenerationType.TABLE,generator="shipmentGen")
     @Column(name = "idShipment", nullable = false)
    public Integer getIdShipment() {
        return idShipment;
    }

    /**
     * @param idShipment the idShipment to set
     */
    public void setIdShipment(Integer idShipment) {
        this.idShipment = idShipment;
    }
    
}
